package test.sum2equalstarget2;

public class Solution {
    public int[] twoSum(int[] numbers, int target) {

        for (int i = 0; i < numbers.length - 1; i++) {
            if (i == 0 || numbers[i - 1] != numbers[i]) {
                int tgt = target - numbers[i];
                int j=numbers.length - 1;
                while (numbers[j] > tgt && j > i) {
                    j--;
                }
                if (j == i) {
                    break;
                }
                if (numbers[j] == tgt) {
                    return new int[]{i + 1, j + 1};
                }
            }
        }
        throw new IllegalArgumentException("not exists");
    }
}
